package com.lineage.data.item_etcitem.add;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Object;
import com.lineage.server.model.L1Party;
import com.lineage.server.model.skill.L1BuffUtil;
import com.lineage.server.model.skill.L1SkillUse;
import com.lineage.server.serverpackets.S_DoActionGFX;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.types.Point;
import com.lineage.server.world.World;
import java.util.Iterator;

public class MagicReel_SpecialBuff extends ItemExecutor {
  private int _type;
  
  public static ItemExecutor get() {
    return new MagicReel_SpecialBuff();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    L1Party party;
    L1SkillUse l1skilluse;
    Iterator<L1PcInstance> iterator, iterator2, iterator3, iterator4, iterator5, iterator6, iterator7, iterator8, iterator9;
    if (pc == null)
      return; 
    if (item == null)
      return; 
    if (pc.isInvisble() || pc.isInvisDelay()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(281));
      return;
    } 
    L1BuffUtil.cancelAbsoluteBarrier(pc);
    pc.getInventory().removeItem(item, 1L);
    switch (this._type) {
      case 1:
        party = pc.getParty();
        if (party == null) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("没有组队无法使用此道具。"));
          return;
        } 
        l1skilluse = new L1SkillUse();
        iterator = party.partyUsers().values().iterator();
        while (iterator.hasNext()) {
          L1PcInstance member = iterator.next();
          if (member.getLocation().isInScreen((Point)pc.getLocation()))
            l1skilluse.handleCommands(pc, 57, member.getId(), member.getX(), member.getY(), 0, 2); 
        } 
        break;
      case 2:
        party = pc.getParty();
        if (party == null) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("没有组队无法使用此道具。"));
          return;
        } 
        l1skilluse = new L1SkillUse();
        iterator2 = party.partyUsers().values().iterator();
        while (iterator2.hasNext()) {
          L1PcInstance member = iterator2.next();
          if (member.getLocation().isInScreen((Point)pc.getLocation()))
            l1skilluse.handleCommands(pc, 79, member.getId(), member.getX(), member.getY(), 0, 2); 
        } 
        break;
      case 3:
        party = pc.getParty();
        if (party == null) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("没有组队无法使用此道具。"));
          return;
        } 
        l1skilluse = new L1SkillUse();
        iterator3 = party.partyUsers().values().iterator();
        while (iterator3.hasNext()) {
          L1PcInstance member = iterator3.next();
          if (member.getLocation().isInScreen((Point)pc.getLocation()))
            l1skilluse.handleCommands(pc, 48, member.getId(), member.getX(), member.getY(), 0, 2); 
        } 
        break;
      case 4:
        party = pc.getParty();
        if (party == null) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("没有组队无法使用此道具。"));
          return;
        } 
        l1skilluse = new L1SkillUse();
        iterator4 = party.partyUsers().values().iterator();
        while (iterator4.hasNext()) {
          L1PcInstance member = iterator4.next();
          if (member.getLocation().isInScreen((Point)pc.getLocation()))
            l1skilluse.handleCommands(pc, 26, member.getId(), member.getX(), member.getY(), 0, 2); 
        } 
        break;
      case 5:
        party = pc.getParty();
        if (party == null) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("没有组队无法使用此道具。"));
          return;
        } 
        l1skilluse = new L1SkillUse();
        iterator5 = party.partyUsers().values().iterator();
        while (iterator5.hasNext()) {
          L1PcInstance member = iterator5.next();
          if (member.getLocation().isInScreen((Point)pc.getLocation()))
            l1skilluse.handleCommands(pc, 42, member.getId(), member.getX(), member.getY(), 0, 2); 
        } 
        break;
      case 6:
        party = pc.getParty();
        if (party == null) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("没有组队无法使用此道具。"));
          return;
        } 
        l1skilluse = new L1SkillUse();
        iterator6 = party.partyUsers().values().iterator();
        while (iterator6.hasNext()) {
          L1PcInstance member = iterator6.next();
          if (member.getLocation().isInScreen((Point)pc.getLocation()))
            l1skilluse.handleCommands(pc, 68, member.getId(), member.getX(), member.getY(), 0, 2); 
        } 
        break;
      case 7:
        party = pc.getParty();
        if (party == null) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("没有组队无法使用此道具。"));
          return;
        } 
        l1skilluse = new L1SkillUse();
        iterator7 = party.partyUsers().values().iterator();
        while (iterator7.hasNext()) {
          L1PcInstance member = iterator7.next();
          if (member.getLocation().isInScreen((Point)pc.getLocation()))
            l1skilluse.handleCommands(pc, 55, member.getId(), member.getX(), member.getY(), 0, 2); 
        } 
        break;
      case 8:
        party = pc.getParty();
        if (party == null) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("没有组队无法使用此道具。"));
          return;
        } 
        l1skilluse = new L1SkillUse();
        iterator8 = party.partyUsers().values().iterator();
        while (iterator8.hasNext()) {
          L1PcInstance member = iterator8.next();
          if (member.getLocation().isInScreen((Point)pc.getLocation()))
            l1skilluse.handleCommands(pc, 148, member.getId(), member.getX(), member.getY(), 0, 2); 
        } 
        break;
      case 9:
        party = pc.getParty();
        if (party == null) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("没有组队无法使用此道具。"));
          return;
        } 
        l1skilluse = new L1SkillUse();
        iterator9 = party.partyUsers().values().iterator();
        while (iterator9.hasNext()) {
          L1PcInstance member = iterator9.next();
          if (member.getLocation().isInScreen((Point)pc.getLocation()))
            l1skilluse.handleCommands(pc, 149, member.getId(), member.getX(), member.getY(), 0, 2); 
        } 
        break;
    } 
    pc.sendPacketsAll((ServerBasePacket)new S_DoActionGFX(pc.getId(), 19));
  }
  
  private final L1Character getTarget(L1PcInstance pc, int targetID) {
    if (targetID == pc.getId() || targetID == 0) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(281));
      return null;
    } 
    L1Object target = World.get().findObject(targetID);
    if (target == null || !(target instanceof L1Character)) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(281));
      return null;
    } 
    return (L1Character)target;
  }
  
  public void set_set(String[] set) {
    try {
      this._type = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
  }
}
